package com.qc31.monitorlib.ui.carmonitor

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.qc31.baselib.custom.LeftRightTextView
import com.qc31.baselib.utils.FileUtil
import com.qc31.comlib.TimeUtil
import com.qc31.comlib.entity.HistoryVideo
import com.qc31.monitorlib.R
import com.qc31.monitorlib.uitls.DataUtil

/** @Author Jasper @Time 2020/9/29 @Desc todo */
class HistoryVideoInfoAdapter(private val isTmn: Boolean = true) :
    BaseQuickAdapter<HistoryVideo.Result, BaseViewHolder>(R.layout.item_history_video) {
    init {
        addChildClickViewIds(R.id.iv_video_history)
    }

    override fun convert(holder: BaseViewHolder, item: HistoryVideo.Result) {
        item.run {
            val position = holder.layoutPosition + 1
            val num = if (position < 10) "0$position" else "$position"
            holder.setText(R.id.tv_item_num, num)
            val videoPass: LeftRightTextView = holder.getView(R.id.lr_tv_video_pass)
            val videoStart: LeftRightTextView = holder.getView(R.id.lr_tv_video_start_ime)
            val videoEnd: LeftRightTextView = holder.getView(R.id.lr_tv_video_end_time)
            val videoFile: LeftRightTextView = holder.getView(R.id.lr_tv_video_file_size)
            val videoLong: LeftRightTextView = holder.getView(R.id.lr_tv_video_long)
            videoPass.setRightText(context.getString(R.string.desc_video_pass) + channel)
            videoStart.setRightText(TimeUtil.instance.formatToNormal(startTime))
            videoEnd.setRightText(TimeUtil.instance.formatToNormal(endTime))
            videoFile.setRightText(FileUtil.formatFileSize(fileSize))
            videoLong.setRightText(TimeUtil.instance.formatLongTime(duration))
            if (isTmn) {
                val videoRes: LeftRightTextView = holder.getView(R.id.lr_tv_video_res_type)
                val videoStream: LeftRightTextView = holder.getView(R.id.lr_tv_video_stream_type)
                val videoStorage: LeftRightTextView = holder.getView(R.id.lr_tv_video_storage_type)
                videoRes.visibility = View.VISIBLE
                videoStream.visibility = View.VISIBLE
                videoStorage.visibility = View.VISIBLE
                videoRes.setRightText(DataUtil.getVideoRes(context)[avType].value)
                videoStream.setRightText(DataUtil.getVideoStream(context)[streamType].value)
                videoStorage.setRightText(DataUtil.getVideoStorage(context)[storeType].value)
            }
        }
    }

}